package cn.exrick.xboot.modules.quartz.jobs;

import cn.exrick.xboot.modules.Information.entity.RiverTourHistory;
import cn.exrick.xboot.modules.Information.service.IRiverTourHistoryService;
import lombok.extern.slf4j.Slf4j;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
 * 定时任务
 * @author Exrickx
 */
@Slf4j
public class RiverEndTime implements Job {
      @Autowired
    private IRiverTourHistoryService iRiverTourHistoryService;


    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        log.info("定时处理当天未正确结束数据======开始");
           List<String> riverId= iRiverTourHistoryService.findEndTime();
           for (String s : riverId) {
               // System.out.println(s);
               Map map = new HashMap();
               Date date=new Date();
               SimpleDateFormat temp=new SimpleDateFormat("yyyy-MM-dd");
               SimpleDateFormat temp2=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
               String date2=temp.format(date);
               date2 += " 23:59:59";
               Date parse=null;
               try{
                   parse = temp2.parse(date2);
               }catch (Exception e){
                   e.printStackTrace();
                   System.out.println("字符串转为date发生异常");
               }
               DateFormat formatTo = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
               String format = formatTo.format(parse);

               map.put("id",s);
               map.put("patrol_end_time",format);
               //System.out.println("id="+map.get("id")+"----"+"patrol_end_time"+map.get("patrol_end_time"));
               int i = iRiverTourHistoryService.fingByIdUpdate(map);
               log.info("处理巡河历史id:"+s+"的结果为"+i);
           }
        log.info("定时处理当天未正确结束数据======结束");

    }
}
